using System;
using bitzhuwei.Compiler;

namespace bitzhuwei.JsonFormat {
    partial class CompilerJson {
        /// <summary>
        /// <see cref="LRNode.kind"/> -&gt; <see cref="Action{LRNode, TContext{Json}}"/>
        /// </summary>
        private static readonly Action<LRNode, TContext<Json>>?[]
            @jsonExtractorItems = new Action<LRNode, TContext<Json>>[1/*'¥'*/ + 8/*Vn*/];

        /// <summary>
        /// initialize dict for extractor.
        /// </summary>
        private static void InitializeExtractorItems() {
            var extractorItems = @jsonExtractorItems;

            #region obsolete
            //extractorDict.Add(st.NotYet,
            //(node, context) => {
            // not needed.
            //});
            //extractorDict.Add(st.Error,
            //(node, context) => {
            // nothing to do.
            //});
            //extractorDict.Add(st.blockComment,
            //(node, context) => {
            // not needed.
            //});
            //extractorDict.Add(st.inlineComment,
            //(node, context) => {
            // not needed.
            //});
            #endregion obsolete

            extractorItems[st.@终/*0*/] = static (node, context) => {
                // [-1] Json' = Json ;
                // dumped by user-defined extractor
                context.result = (Json)context.rightStack.Pop();
            }; // end of extractorItems[st.@终/*0*/] = (node, context) => { ... };
            const int lexiVtCount = 13;
            extractorItems[st.Json枝/*14*/ - lexiVtCount] = static (node, context) => {
                System.Diagnostics.Debug.Assert(node.regulation != null);
                switch (node.regulation.index) {
                case 0: { // [0] Json = Object ;
                    // dumped by user-defined extractor
                    var r0 = (List<JsonMember>)context.rightStack.Pop();
                    var left = new Json(r0);
                    context.rightStack.Push(left);
                }
                break;
                case 1: { // [1] Json = Array ;
                    // dumped by user-defined extractor
                    var r0 = (List<JsonValue>)context.rightStack.Pop();
                    var left = new Json(r0);
                    context.rightStack.Push(left);
                }
                break;
                default: throw new NotImplementedException();
                }
            }; // end of extractorItems[st.Json枝/*14*/ - lexiVtCount] = (node, context) => { ... };
            extractorItems[st.Object枝/*15*/ - lexiVtCount] = static (node, context) => {
                System.Diagnostics.Debug.Assert(node.regulation != null);
                switch (node.regulation.index) {
                case 2: { // [2] Object = '{' '}' ;
                    // dumped by user-defined extractor
                    var r0 = (Token)context.rightStack.Pop();// reserved word is omissible
                    var r1 = (Token)context.rightStack.Pop();// reserved word is omissible
                    var left = new List<JsonMember>();
                    context.rightStack.Push(left);
                }
                break;
                case 3: { // [3] Object = '{' Members '}' ;
                    // dumped by user-defined extractor
                    var r0 = (Token)context.rightStack.Pop();// reserved word is omissible
                    var r1 = (List<JsonMember>)context.rightStack.Pop();
                    var r2 = (Token)context.rightStack.Pop();// reserved word is omissible
                    var left = r1;
                    context.rightStack.Push(left);
                }
                break;
                default: throw new NotImplementedException();
                }
            }; // end of extractorItems[st.Object枝/*15*/ - lexiVtCount] = (node, context) => { ... };
            extractorItems[st.Array枝/*16*/ - lexiVtCount] = static (node, context) => {
                System.Diagnostics.Debug.Assert(node.regulation != null);
                switch (node.regulation.index) {
                case 4: { // [4] Array = '[' ']' ;
                    // dumped by user-defined extractor
                    var r0 = (Token)context.rightStack.Pop();// reserved word is omissible
                    var r1 = (Token)context.rightStack.Pop();// reserved word is omissible
                    var left = new List<JsonValue>();
                    context.rightStack.Push(left);
                }
                break;
                case 5: { // [5] Array = '[' Elements ']' ;
                    // dumped by user-defined extractor
                    var r0 = (Token)context.rightStack.Pop();// reserved word is omissible
                    var r1 = (List<JsonValue>)context.rightStack.Pop();
                    var r2 = (Token)context.rightStack.Pop();// reserved word is omissible
                    var left = r1;
                    context.rightStack.Push(left);
                }
                break;
                default: throw new NotImplementedException();
                }
            }; // end of extractorItems[st.Array枝/*16*/ - lexiVtCount] = (node, context) => { ... };
            extractorItems[st.Members枝/*17*/ - lexiVtCount] = static (node, context) => {
                System.Diagnostics.Debug.Assert(node.regulation != null);
                switch (node.regulation.index) {
                case 6: { // [6] Members = Members ',' Member ;
                    // dumped by user-defined extractor
                    var r0 = (JsonMember)context.rightStack.Pop();
                    var r1 = (Token)context.rightStack.Pop();// reserved word is omissible
                    var r2 = (List<JsonMember>)context.rightStack.Pop();
                    var left = r2;
                    left.Add(r0);
                    context.rightStack.Push(left);
                }
                break;
                case 7: { // [7] Members = Member ;
                    // dumped by user-defined extractor
                    var r0 = (JsonMember)context.rightStack.Pop();
                    var left = new List<JsonMember>();
                    left.Add(r0);
                    context.rightStack.Push(left);
                }
                break;
                default: throw new NotImplementedException();
                }
            }; // end of extractorItems[st.Members枝/*17*/ - lexiVtCount] = (node, context) => { ... };
            extractorItems[st.Elements枝/*18*/ - lexiVtCount] = static (node, context) => {
                System.Diagnostics.Debug.Assert(node.regulation != null);
                switch (node.regulation.index) {
                case 8: { // [8] Elements = Elements ',' Element ;
                    // dumped by user-defined extractor
                    var r0 = (JsonValue)context.rightStack.Pop();
                    var r1 = (Token)context.rightStack.Pop();// reserved word is omissible
                    var r2 = (List<JsonValue>)context.rightStack.Pop();
                    var left = r2;
                    left.Add(r0);
                    context.rightStack.Push(left);
                }
                break;
                case 9: { // [9] Elements = Element ;
                    // dumped by user-defined extractor
                    var r0 = (JsonValue)context.rightStack.Pop();
                    var left = new List<JsonValue>();
                    left.Add(r0);
                    context.rightStack.Push(left);
                }
                break;
                default: throw new NotImplementedException();
                }
            }; // end of extractorItems[st.Elements枝/*18*/ - lexiVtCount] = (node, context) => { ... };
            extractorItems[st.Member枝/*19*/ - lexiVtCount] = static (node, context) => {
                System.Diagnostics.Debug.Assert(node.regulation != null);
                switch (node.regulation.index) {
                case 10: { // [10] Member = 'string' ':' Value ;
                    // dumped by user-defined extractor
                    var r0 = (JsonValue)context.rightStack.Pop();
                    var r1 = (Token)context.rightStack.Pop();// reserved word is omissible
                    var r2 = (Token)context.rightStack.Pop();
                    Utility.TryStripOff(r2.value, out var key);
                    var left = new JsonMember(key, value: r0);
                    context.rightStack.Push(left);
                }
                break;
                default: throw new NotImplementedException();
                }
            }; // end of extractorItems[st.Member枝/*19*/ - lexiVtCount] = (node, context) => { ... };
            /*
            extractorItems[st.Element枝(20) - lexiVtCount] = static (node, context) => {
                System.Diagnostics.Debug.Assert(node.regulation != null);
                switch (node.regulation.index) {
                case 11: { // [11] Element = Value ;
                    // dumped by DefaultExtractor
                    // var r0 = (VnValue)context.rightStack.Pop();
                    // var left = new VnElement(r0);
                    // context.rightStack.Push(left);
                }
                break;
                default: throw new NotImplementedException();
                }
            }; // end of extractorItems[st.Element枝(20) - lexiVtCount] = (node, context) => { ... };
            */
            extractorItems[st.Value枝/*21*/ - lexiVtCount] = static (node, context) => {
                System.Diagnostics.Debug.Assert(node.regulation != null);
                switch (node.regulation.index) {
                case 12: { // [12] Value = 'null' ;
                    // dumped by user-defined extractor
                    var r0 = (Token)context.rightStack.Pop();
                    var left = new JsonValue(JsonValue.Kind.Null, r0.value);
                    context.rightStack.Push(left);
                }
                break;
                case 13: { // [13] Value = 'true' ;
                    // dumped by user-defined extractor
                    var r0 = (Token)context.rightStack.Pop();
                    var left = new JsonValue(JsonValue.Kind.True, r0.value);
                    context.rightStack.Push(left);
                }
                break;
                case 14: { // [14] Value = 'false' ;
                    // dumped by user-defined extractor
                    var r0 = (Token)context.rightStack.Pop();
                    var left = new JsonValue(JsonValue.Kind.False, r0.value);
                    context.rightStack.Push(left);
                }
                break;
                case 15: { // [15] Value = 'number' ;
                    // dumped by user-defined extractor
                    var r0 = (Token)context.rightStack.Pop();
                    var left = new JsonValue(JsonValue.Kind.Number, r0.value);
                    context.rightStack.Push(left);
                }
                break;
                case 16: { // [16] Value = 'string' ;
                    // dumped by user-defined extractor
                    var r0 = (Token)context.rightStack.Pop();
                    var left = new JsonValue(JsonValue.Kind.String, r0.value);
                    context.rightStack.Push(left);
                }
                break;
                case 17: { // [17] Value = Object ;
                    // dumped by user-defined extractor
                    var r0 = (List<JsonMember>)context.rightStack.Pop();
                    var left = new JsonValue(r0);
                    context.rightStack.Push(left);
                }
                break;
                case 18: { // [18] Value = Array ;
                    // dumped by user-defined extractor
                    var r0 = (List<JsonValue>)context.rightStack.Pop();
                    var left = new JsonValue(r0);
                    context.rightStack.Push(left);
                }
                break;
                default: throw new NotImplementedException();
                }
            }; // end of extractorItems[st.Value枝/*21*/ - lexiVtCount] = (node, context) => { ... };

        }
    }
}